package io.shuttle.mbe.api

import io.shuttle.mbe.api.annotation.ChromeMinVersion
import io.shuttle.mbe.api.types.VoidFunction
import io.shuttle.mbe.core.Promise

////////////////////
// Search
////////////////////
/**
 * Use the `Browser.search` API to search via the default provider.
 *
 * Permissions: "search"
 * @since Chrome 87
 */
@ChromeMinVersion(87)
interface Search {
    /**
     * Used to query the default search provider. In case of an error, runtime.lastError will be set.
     * @param options search configuration options.
     * @return The `query` method provides its result via callback or returned as a `Promise` (MV3 only). It has no parameters.
     */
    @ChromeMinVersion(96)
    fun query(queryInfo: QueryInfo, callback: VoidFunction? = null): Promise<Void>

    enum class Disposition {
        // Specifies that the search results display in the calling tab or the tab from the active browser.
        CURRENT_TAB,

        // Specifies that the search results display in a new tab.
        NEW_TAB,

        // Specifies that the search results display in a new window.
        NEW_WINDOW
    }

    data class QueryInfo(
        // Location where search results should be displayed. CURRENT_TAB is the default.
        var disposition: Disposition? = Disposition.CURRENT_TAB,
        // Location where search results should be displayed. tabId cannot be used with disposition.
        var tabId: Number?,
        // String to query with the default search provider.
        var text: String,
    )
}